package com.hex.ds.hdrs.calendar.controller;

import com.hex.bigdata.hbda.annotation.Log;
import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.calendar.dto.WorkCalendarDto;
import com.hex.ds.hdrs.calendar.po.WorkCalendar;
import com.hex.ds.hdrs.calendar.service.WorkCalendarService;
import com.hex.ds.hdrs.common.page.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/workCalendar")
@Api(tags = "应用管理")
@Slf4j
public class WorkCalendarController {

    @Autowired
    private WorkCalendarService workCalendarService;

    @ApiOperation("分页查找工作日期")
    @GetMapping("/selectPages")
    public ResponseEntity<Object> selectPages(Page page, WorkCalendar workCalendar) {
        log.debug("【进入了WorkCalendarController的selectPages】workCalendar={}", workCalendar);
        PageData data = new PageData(this.workCalendarService.selectPages(workCalendar, page), page);
        return new ResponseEntity(data, HttpStatus.OK);
    }

    @ApiOperation("删除")
    @PostMapping("/del")
    @Log("工作日历删除")
    public ResponseEntity<Object> del(@RequestBody List<String> pkIds) {
        log.debug("【进入了WorkCalendarController的del】pkIds: {}", pkIds);
        this.workCalendarService.del(pkIds);
        return new ResponseEntity("删除成功", HttpStatus.OK);
    }

    @ApiOperation("添加工作日历")
    @PostMapping("/add")
    @Log("工作日历新增")
    public ResponseEntity<Object> add(@RequestBody WorkCalendarDto workCalendarDto) {
        log.debug("【进入了WorkCalendarController的add】workCalendarDto: {}", workCalendarDto);
        this.workCalendarService.add(workCalendarDto);
        return new ResponseEntity("新增成功", HttpStatus.OK);
    }

    @ApiOperation("更新默认工作日")
    @PostMapping("/addDefaultWorkCalendar")
    @Log("更新默认工作日")
    public ResponseEntity<Object> addDefaultWorkCalendar(@RequestBody List<String> defaultWorkDates) {
        log.debug("【进入了WorkCalendarController的addDefaultWorkCalendar】defaultWorkDates: {}", defaultWorkDates);
        this.workCalendarService.addDefaultCalendar(defaultWorkDates);
        return new ResponseEntity("新增成功", HttpStatus.OK);
    }

    @ApiOperation("通过id查找当前工作日历")
    @GetMapping("/goEdit")
    public ResponseEntity<Object> goEdit(@RequestParam String dateTime) {
        log.debug("【进入了WorkCalendarController的goEdit】pkId: {}", dateTime);
        WorkCalendarDto workCalendar = this.workCalendarService.goEdit(dateTime);
        return new ResponseEntity(workCalendar, HttpStatus.OK);
    }

    @ApiOperation("获取默认工作日")
    @GetMapping("/getDefaultWorkCalendar")
    public ResponseEntity<Object> getDefaultWorkCalendar() {
        log.debug("【进入了WorkCalendarController.getDefaultWorkCalendar】");
        return new ResponseEntity(workCalendarService.getDefaultWorkCalendar(), HttpStatus.OK);
    }

    @ApiOperation("修改")
    @PostMapping("/edit")
    public ResponseEntity<Object> edit(@RequestBody WorkCalendarDto workCalendarDto) {
        log.debug("【进入了WorkCalendarController的edit】workCalendarDto: {}", workCalendarDto);
        this.workCalendarService.edit(workCalendarDto);
        return new ResponseEntity("修改成功", HttpStatus.OK);
    }

    @ApiOperation("日期查重")
    @PostMapping("/checkData")
    public ResponseEntity<Object> checkData(@RequestBody WorkCalendar workCalendar) {
        log.debug("【进入了WorkCalendarController的checkData】workCalendar: {}", workCalendar);
        boolean result = this.workCalendarService.checkData(workCalendar);
        return new ResponseEntity(result, HttpStatus.OK);
    }
}
